var timestamp = new Date().getTime();

/*if ($.blockUI) {
 $('.container').ajaxStart(
 function (){
  $('.container').block({
            message: '<strong>&nbsp;Espere&nbsp;<img src="./images/loader.gif"></strong>',
            css: {
                border: '1px solid #a00'
            }
        });
 }
 );//.ajaxStop($.unblockUI());
}*/

function get_value(purl, pparameters) {
    var valor = 'N/A_';

    if ($.blockUI) {
        $.blockUI.defaults.baseZ = 200000;
        $('.container').block({
            theme:     true,
            title:    'Espere',
            message: '<strong>&nbsp;Espere&nbsp;<img src="./images/loader.gif"></strong>',
            css: {
                border: '1px solid #a00'
            }
        });
    }

    $.ajax({
        url: base_url + 'index.php/' + purl,
        type: 'POST',
        data: pparameters,
        async: false,
        cache: false,
        dataType: 'text',
        timeout: 30000,
        error: function(a, b) {
            valor = b;
        },
        success: function(msg) {
            valor = msg;
        }
    });
    if ($.blockUI) {
        $('.container').unblock();
    }

    document.body.style.cursor="wait";
    setTimeout(function(){
        document.body.style.cursor="default";
    },400);
    return valor;
}

function get_object(purl, pparameters) {
    var t = get_value(purl, pparameters);
    var j = eval('(' + t + ')');
    return j;
}

function redirect_to(purl) {
    setTimeout(function() {
        window.location.href = base_url + 'index.php/' + purl;
    },
    0);
}

function open_in_new(purl){
 var now = new Date();
 window.open(base_url + 'index.php/' + purl,"_new" + now.getSeconds());
}

function trim(inputString) {
    if (typeof inputString != "string") {
        return inputString;
    }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") {
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
    }
    return retValue;
}